define(function (require) {
var zsApp= require('app');  
require('selectCache','angularFileUpload');
zsApp.controller('applicationCtrl', ['$scope', '$http', '$timeout', 'FileUploader', 'selectCache', 'empSelectCache', 'promptCache', function($scope, $http, $timeout, FileUploader, selectCache, empSelectCache, promptCache) {

	// pagination
	$scope.paginationConf = {
        currentPage		: 1,
        totalItems		: 10,
        itemsPerPage	: 10,
        pagesLength		: 15,
        perPageOptions	: [10, 20, 30, 40, 50],
        onChange: function(){ 
        	var self = this,
        		pagingData = {
	        		pageNumber  : self.currentPage,  
					pageSize 	: self.itemsPerPage,  
	        	};	
	
			$http
			({
				url  	: $scope.zsUrl+'digitalhome-boss/open/appManage/getList',
				method 	: 'POST',


			}).success(function(res) { console.log(res);

				if(res.result_code != '0000') {
                    $scope.isNoData = false;
                    return false;
                }

				// 表格数据
				$scope.tabVal = res.result;
				// 遍历每条数据对应的ID
				angular.forEach($scope.tabVal, function(obj, i) {
					$scope.dataID[i] = obj.appId;
				});
				// 总共有多少条数据
				self.totalItems = res.length;

			}).error(function(err) {
				console.log(err);
			});
        }
    };	

    // 上传图片
    $scope.uploader = new FileUploader();

    var uploader = $scope.uploader = new FileUploader({
        url         : 'http://localhost:8080/233',
        queueLimit  : 1,   //文件个数
    });

    // newlyAdded: show data
    $scope.newlyAdded = function() {

        // 初始化
        $scope.master0 = false;
        $scope.master1 = false;
        empSelectCache.init();

    	$http
    	({
    		url 	: $scope.zsUrl+'digitalhome-boss/open/appManage/addInit',
			method 	: 'POST',
			data 	: { optType : 1 },

    	}).success(function(res) {

    		// 唯一标识
    		$scope.newlyAdded_appKey = res.result.appKey;
    		// 密钥
    		$scope.newlyAdded_appSecret = res.result.appSecret;

    		// 许可类型
    		$scope.authType = [];		// sysValue displayName
    		$scope.remSysVal = [];		// sysValue array
    		angular.forEach(res.result.authType, function(obj, i) {
    			$scope.authType[i] = { 'sysVal' : obj.sysValue, 'displayName' : obj.displayName };
    		});

            // 后台管理服务( 当两个服务都有时 )
            $scope.serviceTypeName0 = res.result.scopes[0].serviceTypeName;     // 服务名（show to user ）
            $scope.scopes0 = res.result.scopes[0].scopesTypeVo;                 // 该服务下的所有子服务（show to user ）
            // 文章管理服务( 当两个服务都有时 )
            $scope.serviceTypeName1 = res.result.scopes[1].serviceTypeName;     // 服务名（show to user ）
            $scope.scopes1 = res.result.scopes[1].scopesTypeVo;                 // 该服务下的所有子服务（show to user ）

            // 储存 后台管理服务( 当两个服务都有时 )的所有子服务的服务编码
            $scope.scopesTypeVo0 = [];
            angular.forEach($scope.scopes0, function(obj, i) {
                $scope.scopesTypeVo0[i] = obj.scopesCode;
            });

            // 储存 文章管理服务( 当两个服务都有时 )的所有子服务的服务编码
            $scope.scopesTypeVo1 = [];
            angular.forEach($scope.scopes1, function(obj, i) {
                $scope.scopesTypeVo1[i] = obj.scopesCode;
            });

            var scopesTypeVo  = [],
                scopesTypeVo0 = [],
                scopesTypeVo1 = [],
                bool0 = false, 
                bool1 = false;

            // 至少选中一个
            $scope.hasSelect = 0;
            // 当一个都不勾选的时候，全选复选框不勾选
            $scope.cancelSelectAll0 = 0;
            $scope.cancelSelectAll1 = 0;

            //  应用管理
            $scope.operationNewlyAdded = function() {

                // url
                var newlyAddedUrl = 'open/appManage/add';

                // 全选 
                $scope.selectAll= function (bool, num) {
                    
                    // 后台管理服务( 当两个服务都有时 )，用于标记
                    if( bool && num==0 ) {
                        bool0 = true;
                        
                        if(bool1) {
                            $scope.hasSelect = $scope.hasSelect-res.result.scopes[0].scopesTypeVo.length;
                        }else {
                            $scope.hasSelect = 0;
                            $scope.hasSelect = $scope.hasSelect-res.result.scopes[0].scopesTypeVo.length;
                        }
                        
                        console.error($scope.hasSelect);
                    }
                    else if( !bool && num==0 ) {
                        bool0 = false;
                        $scope.hasSelect = $scope.hasSelect+res.result.scopes[0].scopesTypeVo.length;
                        console.error($scope.hasSelect);
                    }

                    // 文章管理服务( 当两个服务都有时 )，用于标记
                    if( bool && num==1 ) {
                        bool1 = true;
                        if(bool0){
                            $scope.hasSelect = $scope.hasSelect-res.result.scopes[1].scopesTypeVo.length;
                        }else {
                            $scope.hasSelect = 0;
                            $scope.hasSelect = $scope.hasSelect-res.result.scopes[1].scopesTypeVo.length;
                        }
                        
                        console.error($scope.hasSelect);
                    }
                    else if( !bool && num==1 ) {
                        bool1 = false;
                        $scope.hasSelect = $scope.hasSelect+res.result.scopes[1].scopesTypeVo.length;        
                        console.error($scope.hasSelect);
                    }

                    // 储存后台管理服务的所有子服务
                    if( bool && num==0 ) {
                        scopesTypeVo0 = $scope.scopesTypeVo0;
                    }
                    else if( !bool && num==0 ) {
                        scopesTypeVo0 = [];
                    }

                    // 储存文章管理服务的所有子服务
                    if( bool && num==1 ) {
                        scopesTypeVo1 = $scope.scopesTypeVo1;
                    }
                    else if( !bool && num==1 ) {
                        scopesTypeVo1 = [];
                    }

                    // 合并两个服务的所有子服务到一个数组
                    scopesTypeVo = scopesTypeVo0.concat(scopesTypeVo1);

                    empSelectCache.selectAll(scopesTypeVo, bool);
                };

                // 单选或多选
                $scope.select= function (selectObj, bool, num) { 

                    if(bool) {
                        $scope.hasSelect--;
                    }else if(!bool||bool==undefined){
                        $scope.hasSelect++;
                    }

                    // 后台管理服务( 当两个服务都有时 )，用于标记
                    if( (!bool||bool==undefined) && num==0 ) {
                        $scope.cancelSelectAll0++;
                        $scope.isCheck0 = false;
                        if( $scope.cancelSelectAll0 == res.result.scopes[0].scopesTypeVo.length ) {
                            $scope.master0 = false;
                        }
                        if( $scope.cancelSelectAll0 > res.result.scopes[0].scopesTypeVo.length ) {        
                            $scope.cancelSelectAll0 = res.result.scopes[0].scopesTypeVo.length;
                        }
                    }else if( bool && num==0 ) {
                        $scope.cancelSelectAll0--;
                        if($scope.cancelSelectAll0==0) {
                            $scope.isCheck0 = true;
                            $scope.master0 = true;
                        }
                    }

                    // 文章管理服务( 当两个服务都有时 )，用于标记
                    if( (!bool||bool==undefined) && num==1 ) {
                        $scope.cancelSelectAll1++;
                        $scope.isCheck1 = false;
                        if( $scope.cancelSelectAll1 == res.result.scopes[1].scopesTypeVo.length ) {
                            $scope.master1 = false;
                        }
                        if( $scope.cancelSelectAll1 > res.result.scopes[1].scopesTypeVo.length ) {        
                            $scope.cancelSelectAll1 = res.result.scopes[1].scopesTypeVo.length;
                        }
                    }else if( bool && num==1 ) {
                        $scope.cancelSelectAll1--;
                        if($scope.cancelSelectAll1==0) {
                            $scope.isCheck1 = true;
                            $scope.master1 = true;
                        }
                    }

                    var selectId = selectObj.scopesCode;

                    empSelectCache.select(selectId, bool);    
                }; 

                // submitNewlyAdded
                $scope.submitNewlyAdded= function () {
                    
                    var newlyAddedData = {
                        appName         : $scope.newlyAdded_appName,
                        appKey          : $scope.newlyAdded_appKey,
                        appSecret       : $scope.newlyAdded_appSecret,
                        scope           : '',
                        appType         : $scope.newlyAdded_appType,         
                        status          : $scope.newlyAdded_status,  
                        appUri          : $scope.newlyAdded_appUri, 
                        appIp           : $scope.newlyAdded_appIp,
                        authType        : 'code',
                        grantType       : $scope.sysValue,
                        appSummary      : $scope.newlyAdded_appSummary,
                    };

                    empSelectCache.submitNewlyAdded(newlyAddedData, newlyAddedUrl);

                    reloadTable();
                };
            };


    	}).error(function(err) {
    		console.log(err);
    	});
    };

    // get selected sysValue
    $scope.hasSyaVal = 0;                   // 至少选中一个
    $scope.getSysVal = function(bool, sysVal, i) {

    	if( bool ) {
    		$scope.remSysVal.push($scope.authType[i].sysVal);
            $scope.hasSyaVal--;
    	}else {
    		
            for( var i in $scope.remSysVal ) {
                if( $scope.remSysVal[i] == sysVal ) {
                    $scope.remSysVal.splice(i,1);
                }
            }
            $scope.hasSyaVal++;
    	}
    	$scope.sysValue = $scope.remSysVal.join(',');
    };

    // details
    $scope.details = function(i) {

    	$http({
    		url 	: $scope.zsUrl+'digitalhome-boss/open/appManage/getAppsInfo/'+$scope.dataID[i],
    		method 	: 'GET',

    	}).success(function(res) {	console.log(res);

    		if( '0000' != res.result_code ) {
    			return false;
    		}

            $scope.details_appName        = res.result.appName;
            $scope.details_appKey         = res.result.appKey;
            $scope.details_appSecret      = res.result.appSecret;
            $scope.details_appImage       = res.result.appImage;
            $scope.details_appType        = res.result.appType;
            $scope.details_status         = res.result.status;
            $scope.details_appUri         = res.result.appUri;
            $scope.details_appIp          = res.result.appIp;
            $scope.details_appKey         = res.result.appKey;
            $scope.details_appSummary     = res.result.appSummary;

            // 许可类型
            var grantType = res.result.grantType.split(',');
            $scope.grantTypeArr = [];
            for(var i in res.authType) {
                for(var j in grantType) {
                    if( res.authType[i].sysValue == grantType[j] ) {
                        $scope.grantTypeArr.push(res.authType[i].displayName);
                    }
                }
            };

            // 授权范围
            var scope = res.result.scope.split(',');
            $scope.scope0Arr = [];
            $scope.scope1Arr = [];
            
            // 后台管理服务( 当两个服务都有时 )
            for(var i in res.scopes[0].scopesTypeVo) {
                for(var j in scope) {
                    if( res.scopes[0].scopesTypeVo[i].scopesCode == scope[j] ) {
                        $scope.scope0Arr.push(res.scopes[0].scopesTypeVo[i].scopeName);
                    }
                }
            };
            $scope.serviceTypeName0 = res.scopes[0].serviceTypeName;

            // 文章管理服务( 当两个服务都有时 )
            for(var i in res.scopes[1].scopesTypeVo) {
                for(var j in scope) {
                    if( res.scopes[1].scopesTypeVo[i].scopesCode == scope[j] ) {
                        $scope.scope1Arr.push(res.scopes[1].scopesTypeVo[i].scopeName);
                    }
                }
            };
            $scope.serviceTypeName1 = res.scopes[1].serviceTypeName;

            // 判断是否有第一个服务（有则显示）
            $scope.isScope0Arr = $scope.scope0Arr.length?true:false;

            // 判断是否有第二个服务（有则显示）
            $scope.isScope1Arr = $scope.scope1Arr.length?true:false;
            

    	}).error(function(err) {
    		console.log(err);
    	});
    };

    // edit: show data
    $scope.edit = function(i) {

        empSelectCache.init();

        // 许可类型
        $scope.edit_hasSyaVal = 0;          // 至少选中一个

        // 默认不全选
        $scope.isSelectedAll0 = false;
        $scope.isSelectedAll1 = false;
        

        $http({
            url     : $scope.zsUrl+'digitalhome-boss/open/appManage/getAppsInfo/'+$scope.dataID[i],
            method  : 'GET',

        }).success(function(res) {  console.log(res);

            if( '0000' != res.result_code ) {
                return false;
            }

            $scope.edit_appId          = $scope.dataID[i];
            $scope.edit_appName        = res.result.appName;
            $scope.edit_appKey         = res.result.appKey;
            $scope.edit_appSecret      = res.result.appSecret;
            $scope.edit_appImage       = res.result.appImage;
            $scope.edit_appType        = res.result.appType;
            $scope.edit_status         = res.result.status;
            $scope.edit_appUri         = res.result.appUri;
            $scope.edit_appIp          = res.result.appIp;
            $scope.edit_appKey         = res.result.appKey;
            $scope.edit_appSummary     = res.result.appSummary;

            // 应用类型
            $scope.editAppType = 
            [
                { 'id': 0, 'name': '普通应用' },
                { 'id': 1, 'name': '内部站点' },
            ];

            // 应用状态
            $scope.editAppStatus = 
            [
                { 'id': 0, 'name': '待审核' },
                { 'id': 1, 'name': '正常' },
                { 'id': 2, 'name': '冻结' },
                { 'id': 3, 'name': '逻辑删除' },
                { 'id': 4, 'name': '不合格' },
            ];

            /*********************** 许可类型 ***********************/
            // 许可类型（所有）
            $scope.edit_authType = [];           // sysValue 
            $scope.edit_remSysVal = [];          // sysValue array
            angular.forEach(res.authType, function(obj, i) {
                $scope.edit_authType[i] = { 'sysVal' : obj.sysValue, 'displayName' : obj.displayName };
            });

            // 许可类型（默认选中）
            var defAuthType = res.result.grantType.split(','); 

            // 默认勾选 许可类型
            $scope.isSelectedAuthType = function(sysVal) {
                return defAuthType.indexOf(sysVal) !=-1;
            };

            // 默认的数据
            $scope.edit_sysValue  = defAuthType;
            $scope.edit_remSysVal = defAuthType;

            // 有几个默认数据就减几
            if($scope.edit_sysValue[0]) {
                $scope.edit_hasSyaVal = $scope.edit_hasSyaVal-$scope.edit_sysValue.length;
            }


            /*********************** 管理服务 ***********************/
            var scopesTypeVo  = [],
                scopesTypeVo0 = [],
                scopesTypeVo1 = [],
                bool0 = false, 
                bool1 = false,
                k0 = 0,
                k1 = 0;

            // 至少选中一个
            $scope.edit_hasSelect = 0;
            // 当一个都不勾选的时候，全选复选框不勾选
            $scope.edit_cancelSelectAll0 = 0;
            $scope.edit_cancelSelectAll1 = 0;

            // 后台管理服务( 当两个服务都有时 )
            $scope.edit_serviceTypeName0 = res.scopes[0].serviceTypeName;
            $scope.edit_scopes0 = res.scopes[0].scopesTypeVo;
            // 文章管理服务( 当两个服务都有时 )
            $scope.edit_serviceTypeName1 = res.scopes[1].serviceTypeName;
            $scope.edit_scopes1 = res.scopes[1].scopesTypeVo;

            // 储存 后台管理服务( 当两个服务都有时 )的所有子服务的服务编码
            $scope.edit_scopesTypeVo0 = [];
            angular.forEach(res.scopes[0].scopesTypeVo, function(obj, i) {
                $scope.edit_scopesTypeVo0[i] = obj.scopesCode;
            });

            // 储存 文章管理服务( 当两个服务都有时 )的所有子服务的服务编码
            $scope.edit_scopesTypeVo1 = [];
            angular.forEach(res.scopes[1].scopesTypeVo, function(obj, i) {
                $scope.edit_scopesTypeVo1[i] = obj.scopesCode;
            });

            // 所有管理服务，默认数据
            var defScopesCode = res.result.scope.split(',');
            empSelectCache.defScopesCodeArr(defScopesCode);

            // 至少有一条默认数据
            isSelectedScopesLen($scope.edit_scopesTypeVo0, defScopesCode, 0);
            isSelectedScopesLen($scope.edit_scopesTypeVo1, defScopesCode, 1);
            $scope.edit_cancelSelectAll0 = k0;
            $scope.edit_cancelSelectAll1 = k1;

            // 后台管理服务( 当两个服务都有时 )，默认勾选
            $scope.isSelected0 = function(scopesCode) {
                return defScopesCode.indexOf(scopesCode)!=-1;
            };

            // 文章管理服务( 当两个服务都有时 )，默认勾选
            $scope.isSelected1 = function(scopesCode) {
                return defScopesCode.indexOf(scopesCode)!=-1;
            };

            isSelectedScopes($scope.edit_scopesTypeVo0, defScopesCode);
            isSelectedScopes($scope.edit_scopesTypeVo1, defScopesCode);

            // 有几个默认数据就减几
            function isSelectedScopes(arr1, arr2) {
                for(var i in arr1) {
                    for(var j in arr2) {
                        if(arr1[i] == arr2[j]) {
                            $scope.edit_hasSelect--;
                        }
                    }
                }
            };

            // 数据长度
            function isSelectedScopesLen(arr1, arr2, num) {
                for(var i in arr1) {
                    for(var j in arr2) {
                        if(arr1[i] == arr2[j]) {
                            if(num==0) {
                                k0++;
                            }else if(num==1) {
                                k1++;
                            }
                        }
                    }
                }
            };

            // 修改
            $scope.operationEdit = function() {

                // url
                var editUrl = 'open/appManage/modify';

                // 全选 
                $scope.selectAll= function (bool, num) { //alert(bool);

                    if(num==0) {        // 后台管理服务( 当两个服务都有时 )，用于标记

                        if(bool) {

                            bool0 = true;
                            $scope.isSelectedAll0 = true;

                            if(bool1) {     // 第二个有全选
                                $scope.edit_hasSelect = -(res.scopes[0].scopesTypeVo.length+res.scopes[1].scopesTypeVo.length);
                            }else {         // 第二个没有全选
                                // $scope.edit_hasSelect = 0;
                                $scope.edit_hasSelect = -res.scopes[0].scopesTypeVo.length;
                            }
                        }
                        else if(!bool) {

                            bool0 = false;
                            $scope.isSelectedAll0 = true;
                            // $scope.edit_master0 = false;
                            console.log($scope.edit_master0);

                            $scope.edit_hasSelect = $scope.edit_hasSelect+res.scopes[0].scopesTypeVo.length;
                        }

                    }
                    else if(num==1) {    // 文章管理服务( 当两个服务都有时 )，用于标记

                        if( bool && num==1 ) {

                            bool1 = true;
                            $scope.isSelectedAll1 = true;

                            if(bool0){          // 第一个有全选
                                $scope.edit_hasSelect = -(res.scopes[0].scopesTypeVo.length+res.scopes[1].scopesTypeVo.length);
                            }else {             // 第一个没有全选
                                // $scope.edit_hasSelect = 0;
                                $scope.edit_hasSelect = -res.scopes[1].scopesTypeVo.length;
                            }
                        }
                        else if( !bool && num==1 ) {

                            bool1 = false;
                            $scope.isSelectedAll1 = true;

                            $scope.edit_hasSelect = $scope.edit_hasSelect+res.scopes[1].scopesTypeVo.length;        
                        }
                    };

                    console.error($scope.edit_hasSelect);

                    // 储存后台管理服务的所有子服务
                    if( bool && num==0 ) {
                        scopesTypeVo0 = $scope.edit_scopesTypeVo0;
                    }
                    else if( !bool && num==0 ) {
                        scopesTypeVo0 = [];
                    }

                    // 储存文章管理服务的所有子服务
                    if( bool && num==1 ) {
                        scopesTypeVo1 = $scope.edit_scopesTypeVo1;
                    }
                    else if( !bool && num==1 ) {
                        scopesTypeVo1 = [];
                    }

                    // 合并两个服务的所有子服务到一个数组
                    scopesTypeVo = scopesTypeVo0.concat(scopesTypeVo1);

                    empSelectCache.selectAll(scopesTypeVo, bool);
                };

                // 单选或多选
                $scope.select= function (selectObj, bool, num) {    //console.log(bool);

                    if(bool) {
                        $scope.edit_hasSelect--;
                    }
                    else {
                        $scope.edit_hasSelect++;
                    }
                    
                    if(num==0) {        // 后台管理服务( 当两个服务都有时 )，用于标记

                        if(!bool) {     // 取消选中
                            $scope.edit_cancelSelectAll0--;
                            $scope.edit_isCheck0 = false;
                            if($scope.edit_cancelSelectAll0==0) {
                                $scope.edit_master0 = false;
                            }
                        }else if(bool) {  // 选中
                            $scope.edit_cancelSelectAll0++;
                            if($scope.edit_cancelSelectAll0==res.scopes[0].scopesTypeVo.length) {
                                $scope.edit_isCheck0 = true;
                                $scope.edit_master0 = true;
                            }
                            // $scope.edit_cancelSelectAll0>res.scopes[0].scopesTypeVo.length?$scope.edit_cancelSelectAll0==res.scopes[0].scopesTypeVo.length:$scope.edit_cancelSelectAll0--;
                        }
                        console.log('0：'+$scope.edit_cancelSelectAll0);
                    }
                    else if(num==1) {        // 文章管理服务( 当两个服务都有时 )，用于标记

                        if(!bool) {     // 取消选中
                            $scope.edit_cancelSelectAll1--;
                            $scope.edit_isCheck1 = false;
                            if($scope.edit_cancelSelectAll1==0) {
                                $scope.edit_master1 = false;
                            }
                        }else if(bool) {    // 选中        
                            $scope.edit_cancelSelectAll1++;
                            if($scope.edit_cancelSelectAll1==res.scopes[1].scopesTypeVo.length) {
                                $scope.edit_isCheck1 = true;
                                $scope.edit_master1 = true;
                            }
                            // $scope.edit_cancelSelectAll1>res.scopes[1].scopesTypeVo.length?$scope.edit_cancelSelectAll1==res.scopes[1].scopesTypeVo.length:$scope.edit_cancelSelectAll1++;
                        }
                        console.log('1：'+$scope.edit_cancelSelectAll1);
                    };

                    // 选中的scopesCode
                    var selectCode = selectObj.scopesCode;
                    empSelectCache.select(selectCode, bool);    
                }; 

                // submitEdit
                $scope.submitEdit= function () {
                    
                    var editData = {
                        appId           : $scope.edit_appId,
                        appName         : $scope.edit_appName,
                        appKey          : $scope.edit_appKey,
                        appSecret       : $scope.edit_appSecret,
                        scope           : '',
                        appType         : $scope.edit_appType,         
                        status          : $scope.edit_status,  
                        appUri          : $scope.edit_appUri, 
                        appIp           : $scope.edit_appIp,
                        authType        : 'code',
                        grantType       : $scope.edit_sysValue.toString(),
                        appSummary      : $scope.edit_appSummary,
                    };

                    empSelectCache.submitEdit(editData, editUrl);
                    
                    $scope.edit_master0 = false;
                    $scope.edit_master1 = false;

                    reloadTable();
                };
            };

        }).error(function(err) {
            console.log(err);
        });
    };

    // get selected sysValue
    $scope.edit_getSysVal = function(bool, sysVal, i) {

        if(bool==undefined) {

            for( var i in $scope.edit_remSysVal ) {
                if( $scope.edit_remSysVal[i] == sysVal ) {
                    $scope.edit_remSysVal.splice(i,1);
                }
            }

            $scope.edit_hasSyaVal++;
        }
        else if( bool ) {
            $scope.edit_remSysVal.push($scope.edit_authType[i].sysVal);
            $scope.edit_hasSyaVal--;
        }else if( bool == false ) {
            
            for( var i in $scope.edit_remSysVal ) {
                if( $scope.edit_remSysVal[i] == sysVal ) {
                    $scope.edit_remSysVal.splice(i,1);
                }
            }

            $scope.edit_hasSyaVal++;
        }
    };

    // delete
    $scope.getDataID = function() {

    	// data length
    	var len = $scope.dataID.length;
    	// param id
    	var whichId = 'appId';
    	// param
    	var whichUrl = 'open/appManage/delete';

    	// multiple selections 
        $scope.selectAll= function (bool, obj) {
            selectCache.selectAll(bool, $scope.dataID);
        };

        //  Single or multiple selections 
        $scope.select= function (selectObj, bool) {   
         	var selectId = selectObj.appId;        
            selectCache.select(selectId, bool, len);    
        }; 

        // check
        $scope.check= function () {
            selectCache.check();
        }; 

        // delete
        $scope.delete= function () { 
            selectCache.delete(whichId, whichUrl);
            reloadTable();
        };
    };

    // reload table
    function reloadTable() {
        $timeout(function() {
            $scope.paginationConf.onChange();
            $scope.master = false;
        },1500);
    };
}])
.directive('appNewlyadded', function() {
	return {
		restrict		: 'E',
		templateUrl		: 'system/openPlatform/application/newlyAdded.html',
		replace			: true,
	}
})
.directive('appDetails', function() {
	return {
		restrict		: 'E',
		templateUrl		: 'system/openPlatform/application/details.html',
		replace			: true,
	}
})
.directive('appEdit', function() {
	return {
		restrict		: 'E',
		templateUrl		: 'system/openPlatform/application/edit.html',
		replace			: true,
	}
})
.directive('appDelete', function() {
    return {
        restrict        : 'E',
        templateUrl     : 'system/openPlatform/application/delete.html',
        replace         : true,
    }
})
.directive('appTable', function() {
    return {
        restrict        : 'E',
        templateUrl     : 'system/openPlatform/application/table.html',
        replace         : true,
    }
});
});